package _2FindAlgorithm.src.BinarySearch;

public class Demo5_BinarySearch_left_return {
    public static void main(String[] args) {
        int[] arr = new int[]{1, 2, 2, 4, 4, 5, 6, 7};
        int i = binarySearchBasic(arr, 3);
        System.out.println(i);
    }

    public static int binarySearchBasic(int[] a, int target) {
        int min = 0;
        int max = a.length - 1;
        while(min <= max) {
            int middle = min + max >>> 1;
            if (target <= a[middle]) {
                max = middle - 1;
            } else if (a[middle] < target) {
                min = middle + 1;
            }
        }
        return min;
    }
}
